﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Text;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using PlugNT.Cms.Core;
using PlugNT.Cms.BLL;
using PlugNT.Cms.Model;
using PlugNT.Cms.Page;

namespace PlugNT.Cms.Web.Admin.Pre_GroupPages
{
    public partial class Admin : AdminPage
    {
        private GroupPages curGroupPages = new GroupPages();
        private int pageSize = 15;

        protected void Page_Load(object sender, EventArgs e)
        {
            //权限检测
            this.CheckPower();

            if (!IsPostBack)
            {
                try
                {
                    Repeater_admin_bind();
                    
                }
                catch (Exception ex) { Response.Redirect("../Message.aspx?message=绑定异常！" + ex.Message + "&z=no"); }
            }
        }


        #region 数据绑定
        void Repeater_admin_bind()
        {
            string t = (Request.QueryString["t"] == null) ? "" : Request.QueryString["t"].Trim();
            string id = (Request.QueryString["id"] == null) ? "0" : Request.QueryString["id"].Trim();
            if (t == "delete")
            {
                curGroupPages.Delete(int.Parse(id));
            }
            string gopage = (Request.QueryString["page"] == null) ? "0" : Request.QueryString["page"].Trim();
            int page = Convert.ToInt32(gopage);

            int recordCount = 0;
            DataTable dt = curGroupPages.GetList(pageSize, (page - 1), false,out recordCount);
            litPager.Text = PlugNT.Common.Pager.Pagination(recordCount, pageSize, page, "Admin.aspx", "page", "", true, true);

            Repeater_admin.DataSource = dt;
            Repeater_admin.DataBind();


        }
        #endregion


        //批量删除
        protected void ImageButton_all_del_Click(object sender, System.Web.UI.ImageClickEventArgs e)
        {

            int nub = 0;
            for (int i = 0; i < Repeater_admin.Items.Count; i++)
            {
                int id = Convert.ToInt32(((HiddenField)Repeater_admin.Items[i].FindControl("hidid")).Value.Trim());
                CheckBox CK = (CheckBox)Repeater_admin.Items[i].FindControl("ID_list");
                if (CK.Checked)
                {
                    if (curGroupPages.Delete(id))
                    {
                        nub += 1;
                    }
                }
            }
            Response.Redirect("../Message.aspx?message=批量删除<b>" + nub + "</b>条信息成功！&z=yes");

        }
    }
}
